<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        function delay() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(22)
                })
            })
        }
        let p = delay().then((res) => {
            console.log('555')
        })

        // async await的作用：可以让我们像写同步代码一样执行我们的异步代码
        //   语法糖
        async function xxx() {
            console.log('top')
            const result = await delay()
            console.log(result)
            const result1 = await delay()
            console.log(result1)
            const result2 = await delay()
            console.log(result2)
            console.log('bottom')
            // console.log('6666')
        }
        //   xxx()

        async function chatRobot() {
            const res = await axios({
                url: 'http://ajax-api.itheima.net/api/robot?spoken=你饿不饿',
            })
            console.log(res)
            const res1 = await axios({
                url: 'http://ajax-api.itheima.net/api/robot?spoken=你要不要吃点啥',
            })
            console.log(res1)
            const res2 = await axios({
                url: 'http://ajax-api.itheima.net/api/robot?spoken=我给你买包子',
            })
            console.log(res2)
        }
        chatRobot()
    </script>
</body>

</html>